<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<c:set var="bp" value="${pageContext.request.contextPath}"/>
<jsp:include page="common/header.jsp"/>
<div id="page-wrapper">
    <div class="row">
        <div class="col-md-12">
            <h1 class="page-header">邮件管理</h1>
        </div>
        <!-- /.col-lg-12 -->
    </div>
    <div class="row">
        <div class="col-md-8">

            <input id="message" type="text" placeholder="请输入邮件内容">
            <input id="active" type="text" placeholder="请输入邮件主题">
            <input id="touser" type="text" placeholder="请输入收件人">

            <button onclick="send()">添加</button>
        </div>

    </div>
</div>

<div id="page-wrapper">
    <div class="row">
        <div class="col-md-12">
            <h1 class="page-header">邮件列表</h1>
        </div>
        <!-- /.col-lg-12 -->
    </div>
    <div class="row">
        <div class="col-md-8">
            <table class="table table-striped table-bordered table-hover">
                <thead>
                <tr>
                    <th style="width: 12%">邮件编号</th>
                    <th style="width: 20%">邮件内容</th>
                    <th style="width: 10%">邮件主题</th>
                    <th style="width: 10%">收件人</th>
                    <td style="width: 10%">时间</td>
                    <td style="width: 10%">发件人</td>
                    <td style="width: 10%">操作</td>
                </tr>
                </thead>
                <tbody>
                <c:forEach items="${maillist}" var="keyword" varStatus="mid">
                    <tr>
                        <td>${keyword.mid}</td>
                        <td>${keyword.message}</td>
                        <td>${keyword.active}</td>
                        <td>${keyword.touser}</td>
                        <td>${keyword.createtime}</td>
                        <td>${keyword.user}</td>
                        <td><button onclick="quierk(${keyword.mid})">删除</button></td>
                    </tr>
                </c:forEach>

                </tbody>
            </table>

        </div>

    </div>
</div>
<!-- /#page-wrapper -->

</div>
<script type="text/javascript">

    function send() {
        var message = $("#message").val()
        var active = $("#active").val()
        var touser = $("#touser").val()
        $.ajax({
            type:"post",
            url:"${bp}/mail/send",
            data:{"message":message,"active":active,"touser":touser},
            success : function (msg) {
                if(msg == 1){
                    alert("添加成功")
                    window.location.reload()
                }else{
                    alert("添加失败")
                }

            }
        })
    }
    function quierk(mid) {
        $.ajax({
            type:"get",
            url:"${bp}/mail/delete",
            data:{"mid":mid},
            success : function (msg) {
                if(msg == 1){
                    alert("删除成功")
                    window.location.reload()
                }else{
                    alert("删除失败")
                }
            }
        })
    }
</script>

<jsp:include page="common/forwer.jsp" />
</body>

</html>